import request from '@/utils/request'
import type {
  ConfigAttributeInfo,
  ConfigAttributeQuery,
  ConfigAttributeExportParams,
  ConfigAttributePageResult,
  ConfigAttributeDeleteParams,
  ConfigAttributeFormData,
  ApiResponse
} from './types'

// 查询通信协议字段属性列表
export function getConfigAttributeList(params: ConfigAttributeQuery): Promise<ApiResponse<ConfigAttributePageResult>> {
  return request({
    url: '/protocol/dataformatProperty/list',
    method: 'get',
    params
  })
}

// 导出通信协议字段属性列表
export function exportConfigAttributeList(params: ConfigAttributeExportParams): Promise<Blob> {
  return request({
    url: '/protocol/dataformatProperty/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  })
}

// 获取通信协议字段属性详细信息
export function getConfigAttributeDetail(propertyId: string): Promise<ApiResponse<ConfigAttributeInfo>> {
  return request({
    url: `/protocol/dataformatProperty/${propertyId}`,
    method: 'get'
  })
}

// 新增通信协议字段属性
export function addConfigAttribute(data: ConfigAttributeFormData): Promise<ApiResponse<void>> {
  return request({
    url: '/protocol/dataformatProperty',
    method: 'post',
    data
  })
}

// 修改通信协议字段属性
export function updateConfigAttribute(data: ConfigAttributeFormData): Promise<ApiResponse<void>> {
  return request({
    url: '/protocol/dataformatProperty',
    method: 'put',
    data
  })
}

// 删除通信协议字段属性
export function deleteConfigAttribute(propertyIds: string[]): Promise<ApiResponse<void>> {
  return request({
    url: `/protocol/dataformatProperty/${propertyIds.join(',')}`,
    method: 'delete'
  })
}

// 批量删除通信协议字段属性
export function batchDeleteConfigAttribute(propertyIds: string[]): Promise<ApiResponse<void>> {
  return request({
    url: `/protocol/dataformatProperty/${propertyIds.join(',')}`,
    method: 'delete'
  })
}